const mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
const Schema = mongoose.Schema;

const bitchinaSchema = new Schema({
    _id: String,
    address: String,
    infohash: String,
    magnet: String,
    port: Number,
    name: String,
    size: Number,
    humanSize: String,
    visitCount: Number,
    isVideo: Boolean,
    files: Schema.Types.Mixed,
    createDate: String,
    lastUpdate: String,
    createTime: Date
})
var options = { promiseLibrary: require('bluebird') };
//mongoose.connect('mongodb://lance:lance@127.0.0.1:27017/spider',{auth:{authdb:"admin"}})
//const db = mongoose.createConnection('mongodb://192.168.128.70/spider', options);
const db = mongoose.createConnection('mongodb://localhost/spider',options);
const Models = {
    bitchina: db.model('bitchina', bitchinaSchema)
};

//const db = mongoose.connection;
db.on('error', function (err) {
    console.log("Db Connection error." + err)
})

db.once('open', function () {
    console.log("Db has Connection");   
})

module.exports = Models

